﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace HslDemo
{
    public partial class Form1 : Form
    {
        //ModbusRtuHelper modbusRtuHelper = new ModbusRtuHelper(1, "Com6", 9600, 8, StopBits.One, Parity.Even, "ABCD");
        ModbusTcpClient tcpHelper = new ModbusTcpClient("127.0.0.1", 502,"CDAB");
        public Form1()
        {
            InitializeComponent();
            // modbusRtuHelper.Open();
            tcpHelper.Open();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // modbusRtuHelper.Read(ModbusRiuDataType.ModbusTcpInt16,3,"0");

            //  object[] a = modbusRtuHelper.ReadArray(ModbusRtuDataType.ModbusTcpInt32, 3, 0, 3);
            //  if (a!=null)
            //  {
            //      int[] b = new int[a.Length];
            //      a.CopyTo(b, 0);
            //  }

            //int c= (int) modbusRtuHelper.Read(ModbusRtuDataType.ModbusTcpInt32, 3, 0);
            //  bool d = (bool)modbusRtuHelper.Read(ModbusRtuDataType.ModbusTcpBool, 1, 0);

            //float a = tcpHelper.Read<float>(3,0);
           List<short>  a = tcpHelper.ReadArray<short>(3, 0, 3);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //int[] b = new int[3] { 123, 123, 123 };
            //object[] a = new object[b.Length];
            //b.CopyTo(a, 0);
            //modbusRtuHelper.WriteArray(ModbusRtuDataType.ModbusTcpInt32, 3, 0, a, 3);
        }
    }
}
